<template>
  <div class="right-sided-bar">
    <el-badge :value="shoppingCart.count" :max="99">
      <div class="bar-button">
        <svg-icon class-name="sided-icon shop" icon-class="jbcshop" @click.stop="handleShopCar" />
        <div class="bar-button__txt">购物车</div>
      </div>
    </el-badge>
    <div class="bar-button">
      <svg-icon class-name="sided-icon service" icon-class="jbcservice" @click.stop="handleService" />
      <div class="bar-button__txt">客服</div>
    </div>
    <div class="bar-button">
      <svg-icon class-name="sided-icon search" icon-class="jbcsearch" @click.stop="handleSearch" />
      <div class="bar-button__txt">搜索</div>
    </div>
    <div class="bar-button">
      <svg-icon class-name="sided-icon top" icon-class="jbcout" @click.stop="handleGoTop" />
      <div class="bar-button__txt">置顶</div>
    </div>
  </div>
</template>

<script setup name="rightSidedBar">
import useShoppingCartStore from '@/components/webCustom/shoppingCart'
import useUserStore from '@/store/modules/user'
const { proxy } = getCurrentInstance()
const userStore = useUserStore()
const router = useRouter()
const shoppingCart = useShoppingCartStore()
const handleShopCar = () => {
  if (shoppingCart.count === 0) {
    proxy.$modal.msg('购物车中还没有商品，请先添加商品!')
  } else {
    router.push({ path: '/shoppingCart' })
  }
}
const handleService = () => {
  window.open(userStore.appInfo.kf, '_blank')
}
const handleSearch = () => {
  router.push({ name: 'type' })
}
const handleGoTop = () => {
  window.scrollTo({ top: 0, behavior: 'smooth' })
}
</script>

<style lang="scss" scoped>
.right-sided-bar {
  position: fixed;
  top: 50%;
  right: 0;
  width: 84px;
  height: 367px;
  margin-top: -183px;
  background: #FFFFFF;
  box-shadow: 0px 2px 10px 0px rgba(204, 204, 204, 0.5);
  border-radius: 20px 0px 0px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 35px 0;
  box-sizing: border-box;
  justify-content: space-between;
  z-index: 900;
}

.bar-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;

  &__txt {
    font-size: var(--jbc-font-size-base);
    color: var(--jbc-font-color);
    margin-top: 5px;
    line-height: 20px;
  }
}

.sided-icon {
  color: var(--jbc-font-color);

  &.top {
    width: 34px;
    height: 31px;
  }

  &.shop {
    width: 30px;
    height: 28px;
  }

  &.service {
    width: 33px;
    height: 35px;
  }

  &.search {
    width: 34px;
    height: 32px;
  }
}
</style>